﻿

''' <summary>
'''冷凝器数据服务类
''' </summary>
''' <remarks></remarks>
Public Class CcapCondenserItemService

    ''' <summary>
    ''' 默认构造函数
    ''' </summary>
    ''' <remarks></remarks>
    Public Sub New()

    End Sub

    ''' <summary>
    ''' 查询隶属机组的冷凝器
    ''' </summary>
    ''' <param name="csId">机组编号</param>
    ''' <returns>冷凝器信息</returns>
    ''' <remarks>数据集表包含字段为：`Id`,`csId`,`name`,`DevId`</remarks>
    Public Function GetCondenser(ByVal csId As Integer)
        Dim ds As DataSet = Nothing
        Dim strSql As String = String.Empty

        strSql = "select `Id`,`csId`,`name`,`csNetId` from tbcccondenser where `csId` =" + csId.ToString()
        Try
            ds = SqlHelper.ExecuteDataset(strSql, Nothing)
        Catch ex As Exception
            ds = Nothing
        End Try

        Return ds
    End Function
    'Public Shared Function DevTypeMaxid(ByVal cp As CcapDevItem) As Integer
    '    Dim strSql As String
    '    strSql = String.Format("Select max(id) from tbcccondenser where csNetid<>'{0}'", cp.NetId)

    '    Dim obj As Object
    '    obj = SqlHelper.ExecuteScalar(strSql, Nothing)

    '    If obj Is Nothing OrElse IsDBNull(obj) Then
    '        Return 0
    '    Else
    '        Return CInt(obj)
    '    End If


    'End Function
    ''' <summary>
    ''' 返回所有冷凝器信息
    ''' </summary>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Public Shared Function GeConGroupList(ByVal netid As Integer) As List(Of CcapCondenserItem)
        Dim il As IList(Of CcapCondenserItem)
        il = New List(Of CcapCondenserItem)

        Dim ds As DataSet

        Dim strSql As String
        strSql = String.Format("SELECT *  FROM tbccCondenser  WHERE  csNetid<>'{0}' order by id", netid)

        ds = TBCC.Utility.SqlHelper.ExecuteDataset(strSql, Nothing)
        If ds.Tables.Count = 0 OrElse ds.Tables(0).Rows.Count = 0 Then
            ds.Clear() : ds.Dispose() : ds = Nothing
            Return Nothing
        End If

        For Each r As DataRow In ds.Tables(0).Rows
            Dim rti As New CcapCondenserItem
            rti.Id = r("id")
            rti.NetId = r("csNetid")
            rti.CondenserName = r("name")
            rti.CsId = r("csId")

            il.Add(rti)

        Next

        Return il

    End Function
    ''' <summary>
    ''' 增加冷凝器信息
    ''' </summary>
    ''' <param name="con"></param>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Public Shared Function AddCondenserItem(ByVal con As CcapCondenserItem) As Boolean
        Dim strSql As String

        Dim tic As New TBCC.Utility.TranstrationItem


        strSql = "Insert into tbcccondenser(id,csNetid,csId,name,RelId) Values(?p0,?p1,?p2,?p3,?p4)"

        Dim p1(4) As System.Data.Common.DbParameter

        p1(0) = New MySql.Data.MySqlClient.MySqlParameter()
        p1(0).ParameterName = "p0" : p1(0).Value = con.Id

        p1(1) = New MySql.Data.MySqlClient.MySqlParameter()
        p1(1).ParameterName = "p1" : p1(1).Value = con.NetId

        p1(2) = New MySql.Data.MySqlClient.MySqlParameter()
        p1(2).ParameterName = "p2" : p1(2).Value = con.CsId

        p1(3) = New MySql.Data.MySqlClient.MySqlParameter()
        p1(3).ParameterName = "p3" : p1(3).Value = con.CondenserName

        p1(4) = New MySql.Data.MySqlClient.MySqlParameter()
        p1(4).ParameterName = "p4" : p1(4).Value = con.RelId

       

        tic.Add(strSql, p1)


        Return TBCC.Utility.SqlHelper.ExecuteTranstration(tic)
    End Function

    ''' <summary>
    ''' 删除冷凝器信息
    ''' </summary>
    ''' <param name="com"></param>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Public Shared Function DelCondenserItem(ByVal com As Integer) As Boolean
        Dim strSql As String

        Dim tic As New TBCC.Utility.TranstrationItem

        strSql = String.Format("delete from tbcccondenser where id='{0}'", com)

        tic.Add(strSql, Nothing)

        Return TBCC.Utility.SqlHelper.ExecuteTranstration(tic)
    End Function
    ''' <summary>
    ''' 更新冷凝器信息
    ''' </summary>
    ''' <param name="com"></param>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Public Shared Function UpdateCondenserItem(ByVal com As CcapCondenserItem) As Boolean

        Dim strSql As String

        Dim tic As New TBCC.Utility.TranstrationItem

        strSql = String.Format("Update tbcccondenser set csNetid='{0}',csId='{1}',name='{2}' where id='{3}'", com.NetId, com.CsId, com.CondenserName, com.Id)

        tic.Add(strSql, Nothing)

        Return TBCC.Utility.SqlHelper.ExecuteTranstration(tic)
    End Function

End Class
